package com.huya.k12.translate.admin.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.huya.k12.translate.service.SVNService;
import com.huya.k12.translate.service.XMLService;

@Controller
@RequestMapping(value="/admin/xml")
public class XMLController {
	
	public final static Map<String,String> countryMap = new HashMap<String,String>();
	static{
		countryMap.put("zh-rCN","中文(zh-rCN)");
		countryMap.put("ar", "阿根廷(ar)");
		countryMap.put("de", "德国(de)");
		countryMap.put("es", "西班牙(es)");
		countryMap.put("fr", "法国(fr)");
		countryMap.put("hi", "北印度(hi)");
		countryMap.put("in", "印度(in)");
		countryMap.put("it", "意大利(it)");
		countryMap.put("ja", "日本(ja)");
		countryMap.put("ko", "韩国(ko)");
		countryMap.put("ms", "马来西亚(ms)");
		countryMap.put("pt","葡萄牙(pt)");
		countryMap.put("ru", "俄国(ru)");
		countryMap.put("th", "泰国(th)");
		countryMap.put("tl", "东帝汶岛(tl)");
		countryMap.put("tr", "土耳其(tr)");
		countryMap.put("ur-rPK", "巴基斯担(ur-rPK)");
		countryMap.put("vi", "越南(vi)");
		countryMap.put("zh-rSG", "中文(zh-rSG)");
		countryMap.put("zh", "中文(zh)");
	}

	@Autowired
	private XMLService xmlService;
	
	@Autowired
	private SVNService svnService;
	
	
	@RequestMapping(value="/main")
	public String main(Model model){
		model.addAttribute("countryMap", countryMap);
		return "/admin/xml/xml-main";
	}
	
	@RequestMapping(value="/export")
	@ResponseBody
	public String export(String countryCode){
		String result = xmlService.exportXML(countryCode);
		return result;
	}
	
	@RequestMapping(value="/import")
	public String importXML(Model model, @RequestParam("file") MultipartFile file, String countryCode){
		xmlService.importXML(file, countryCode);
		return "redirect:/admin/xml/main";
	}
	
	
	@RequestMapping(value="/update")
	@ResponseBody
	public String update(){
		
		svnService.update();
		return null;
	}
	
	
}
